package com.wei.jpush;

import android.app.Application;
import android.app.Notification;
import android.util.Log;

import java.util.HashSet;
import java.util.Set;

import cn.jpush.android.api.BasicPushNotificationBuilder;
import cn.jpush.android.api.CustomPushNotificationBuilder;
import cn.jpush.android.api.JPushInterface;
import cn.jpush.android.api.TagAliasCallback;

/**
 * @author zhangwei
 * @version V1.0
 * @Title: Advanced
 * @Package com.wei.jpush
 * @Description:
 * @date 15/10/26 上午11:00
 */

public class BaseApp extends Application {
    private static final String TAG = BaseApp.class.getSimpleName();
    public static BaseApp app;

    @Override
    public void onCreate() {
        super.onCreate();
        app = this;
        JPushInterface.init(this);
        //开发的时候使用,项目上线的时候记得关掉
        JPushInterface.setDebugMode(true);
        //比如有用户系统的可以设置用户名
        JPushInterface.setAlias(this, "123", new TagAliasCallback() {
            @Override
            public void gotResult(int i, String s, Set<String> set) {
                if (i == 0) {
                    Log.e(TAG, "设置别名成功");
                } else {
                    Log.e(TAG, "设置别名失败!!!");
                }
            }
        });
        //设置标签可以是多个
        Set<String> sets = new HashSet<>();
        sets.add("科技");
        sets.add("娱乐");
        JPushInterface.setTags(this, sets, new TagAliasCallback() {
            @Override
            public void gotResult(int i, String s, Set<String> set) {
            }
        });

        //改变通知栏的样式

        BasicPushNotificationBuilder builder = new BasicPushNotificationBuilder(this);
        //设置状态栏显示的图片
        builder.statusBarDrawable = R.mipmap.last_fm;
        builder.notificationFlags = Notification.DEFAULT_LIGHTS;
        JPushInterface.setDefaultPushNotificationBuilder(builder);

        //设置带编号的通知栏
        BasicPushNotificationBuilder oneBuilder = new BasicPushNotificationBuilder(this);
        oneBuilder.statusBarDrawable = R.mipmap.twitter;
        JPushInterface.setPushNotificationBuilder(2, oneBuilder);

        /**
         * 参数说明
         * 参数一 上线文
         *
         *
         */
        CustomPushNotificationBuilder cusotmBuilder = new CustomPushNotificationBuilder(this, R.layout.customer_notitfication_layout, R.id.icon, R.id.title, R.id.text);
        cusotmBuilder.statusBarDrawable = R.mipmap.facebook;
        JPushInterface.setPushNotificationBuilder(3, cusotmBuilder);
    }

    public static BaseApp getInstance() {
        return app;
    }
}
